home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_3 / a3_i.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  1.4 KB  |  52 lines  |  [MATS/MATL]

  1. echo off;
  2. % NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1994
  3. % To accompany the text:
  4. % NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
  5. % Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
  6. % This free software is complements of the author.
  7.  
  8. % Algorithm 3.i (Inverse of a matrix).
  9. % Section    3.5,    Matrix Inversion, Page 161
  10. % Section    3.6,    Triangular Factorizaton, Page 175
  11. % Uses the result of LU factorization in Section 3.6
  12. echo on; clc; format long; clear
  13.  
  14. % This program finds the inverse of a matrix.
  15.  
  16. % The method involves the formation of  PA = LU
  17.  
  18. % Then a loop is used to solve n equations of the
  19.  
  20. % for  AXj = Ej  for j=1,2,...,n
  21.  
  22. % The vectors Xj will be the columns of the inverse matrix.
  23.  
  24. % Remark. lufact.m and lusolv.m are used for Algorithm 3.i
  25.  
  26. pause % Press any key to continue.
  27.  
  28. clc;
  29. % Find the inverse of the matrix  A  where:
  30.  
  31. A = [ 3   -9    27   -81;
  32.      -4   16   -64   256;
  33.       5  -25   125  -625;
  34.      -6   36  -216  1296];
  35.  
  36. [LU,row] = lufact(A);
  37. [n,n] = size(A);
  38. E = eye(n,n);
  39. for k=1:n,
  40.   C(:,k) = lusolv(LU,E(:,k),row);
  41. end
  42.  
  43. pause % Press any key to continue.
  44.  
  45. Mx1 = 'The LU factorization method is used to invert a matrix.';
  46. Mx2 = 'The matrix is A =';
  47. Mx3 = 'The inverse matrix is C =';
  48. clc,echo off,diary output,...
  49. disp(''),disp(Mx1),disp(''),disp(Mx2),disp(A),...
  50. disp(''),disp(Mx3),disp(C),...
  51. diary off, echo on
  52.